import pygame
import time
import copy

class Box:
    def __init__(self):
        self.x = 200
        self.y = 200
        self.cell_size = 25

        self.data = [
            [2, 1, 1, 1, 1],
            [0, 1, 1, 4, 1],
            [0, 1, 1, 1, 1],
            [0, 1, 1, 1, 1],
            [1, 0, 0, 0, 3],
        ]

    def update(self, key_pressed):
        if key_pressed[pygame.K_UP]:
            self.rotate()
            time.sleep(0.1)

    def draw(self, screen):
        for li, line in enumerate(self.data):
            for ci, cell in enumerate(line):
                if cell == 1:
                    pygame.draw.rect(screen, (0, 138, 230),
                                     (self.x + ci * self.cell_size,
                                      self.y + li * self.cell_size,
                                      self.cell_size, self.cell_size))
                if cell ==2:
                    pygame.draw.rect(screen, (230, 0, 92),
                                     (self.x + ci * self.cell_size,
                                      self.y + li * self.cell_size,
                                      self.cell_size, self.cell_size))
                if cell ==3:
                    pygame.draw.rect(screen,  (0, 204, 0),
                                     (self.x + ci * self.cell_size,
                                      self.y + li * self.cell_size,
                                      self.cell_size, self.cell_size))
                if cell ==4:
                    pygame.draw.rect(screen,  (255, 255, 0),
                                     (self.x + ci * self.cell_size,
                                      self.y + li * self.cell_size,
                                      self.cell_size, self.cell_size))


    def rotate(self):
        # new_data = copy.deepcopy(self.data)
        new_data = [[0 for i in range(5)] for j in range(5)]
        for li, line in enumerate(self.data):
            for ci, cell in enumerate(line):
                new_data[ci][4 - li] = cell
        self.data = new_data

        for li in self.data:
            print(li)
        print("-" * 80)